package com.common.app.utls

import android.view.View
import androidx.viewpager.widget.ViewPager

/**
 * 设置中间放大两边缩小
 */
class ScalePageTransformer : ViewPager.PageTransformer {

    override fun transformPage(page: View, position: Float) {
        var newPosition = position
        if (newPosition < -1) {
            newPosition = -1f
        } else if (position > 1) {
            newPosition = 1f
        }
        val tempScale = if (newPosition < 0) 1 + newPosition else 1 - newPosition
        val slope = (MAX_SCALE - MIN_SCALE) / 1
        val scaleValue = MIN_SCALE + tempScale * slope
        page.scaleX = scaleValue
        page.scaleY = scaleValue
    }

    companion object {
        const val MAX_SCALE = 1.0f
        const val MIN_SCALE = 0.9f
    }
}